package pio.action;
import DBMS.DataBaseManager;
import clases.Contrasena;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author tamerdark
 */
public class CambiarContrasena extends DispatchAction {

  public ActionForward actualizar(ActionMapping mapping, ActionForm form,
          HttpServletRequest request, HttpServletResponse response)
          throws Exception {
      Contrasena c = (Contrasena)form;
      DataBaseManager dbms = DataBaseManager.getInstance();
      if(dbms.actualizarContrasena(c, true)){
          c.setMensaje("Su contraseña ha sido actualizada con éxito");
          return mapping.findForward("success");
      }else{
          c.setMensaje("Los datos introducidos son incorrectos por favor intente de nuevo");
          c.cleanAttributes();
          return mapping.findForward("failure");
      }
  }
  
  public ActionForward page(ActionMapping mapping, ActionForm form,
          HttpServletRequest request, HttpServletResponse response)
          throws Exception {
      Contrasena c = (Contrasena)form;
      c.setCedula((String)request.getSession().getAttribute("cedula"));
      DataBaseManager dbms = DataBaseManager.getInstance();
      return mapping.findForward("page");
  }
}
